﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using Telerik.Web.UI;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class DC_CmdCommitteeDtls : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private object _dataItem = null;
        private CommandDisciplineBLL cmmBLL = new CommandDisciplineBLL();
        private IEmployeeBLL empBLL = new EmployeeBLL();

        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }
        //ReadOnly property.
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        //Initializing the new variable updating ViewState data.
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            IncludeJava();

            if (!IsUserControlPostBack)
            {
                this.ViewState.Add("IsUserControlPostBack", true);
            }

            if (DataItem != null)
            {
                ListCmmPosition();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    EmployeeInfo infoEmp;
                    IList<EmployeeInfo> infoList = empBLL.ListEmployees(DataBinder.Eval(DataItem, "emp_seq").ToString());
                    infoEmp = infoList[0];
                    lblID_emp.Text = infoEmp.Sequence.ToString();
                    lblID_empType.Text = infoEmp.EmployeeType.Sequence.ToString();
                    txtEmployee.Text = infoEmp.Person.FullName;
                    lblPosRef.Text = infoEmp.Position.RefNo;
                    lblPosName.Text = infoEmp.Position.Name;
                    lblClassName.Text = infoEmp.Position.ClassSpecification.Name;
                    lblJobSiteName.Text = infoEmp.Position.JobSite.Name;

                }
                else
                {

                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private void ListCmmPosition()
        {
            DataTable dt;

            dt = cmmBLL.SelectCommitteePosition();

            cmbPosition.DataSource = dt;
            cmbPosition.DataBind();
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            try
            {
                cmmBLL.InsertCommittee(Convert.ToInt32(Request.QueryString["ParSequence"].ToString())
                    , Int32.Parse(lblID_emp.Text)
                    , Int32.Parse(cmbPosition.SelectedValue)
                    , txtRemark.Text.Trim()
                    , ssMng.EmpSeqI);
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                cmmBLL.UpdateCommittee(Convert.ToInt32(lblID.Text.Trim())
                    , Convert.ToInt32(Request.QueryString["ParSequence"].ToString())
                    , Int32.Parse(lblID_emp.Text)
                    , Int32.Parse(cmbPosition.SelectedValue)
                    , txtRemark.Text.Trim()
                    , ssMng.EmpSeqI);
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }


        protected void btnFindEmp_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string st = Hide.Value;
                if (st == "")
                    return;
                EmployeeInfo infoEmp;
                IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
                infoEmp = infoList[0];
                lblID_emp.Text = infoEmp.Sequence.ToString();
                lblID_empType.Text = infoEmp.EmployeeType.Sequence.ToString();
                txtEmployee.Text = infoEmp.Person.FullName;
                lblPosRef.Text = infoEmp.Position.RefNo;
                lblPosName.Text = infoEmp.Position.Name;
                lblClassName.Text = infoEmp.Position.ClassSpecification.Name;
                lblJobSiteName.Text = infoEmp.Position.JobSite.Name;
            }
            catch
            {

            }
        }

        protected void btnFindEmp_Load(object sender, EventArgs e)
        {
            Session["ETID"] = "1";
            btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogEmp.aspx?ETID=" + Session["ETID"].ToString() + "'" + ",'../frmIframe.html',700,500)");
        }
    }
}